/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.lardocelar.core.comando;

import br.com.lardocelar.core.Comando;
import br.com.lardocelar.core.ServicoSistema;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.media.NoPlayerException;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;

/**
 *
 * @author LeandroL
 */
public class FazerConta implements Comando{

    @Override
    public String[] getComando() {
        return new String[]{"fazer","conta"};
    }

    @Override
    public void Acionar() {
        try {
            ServicoSistema.Falar("Pode falar");
            String palavar = "";
            //List<String> conta = new ArrayList<>();
            String conta = "";
            while(!palavar.equalsIgnoreCase("igual") && !palavar.equalsIgnoreCase("="))
            {
                palavar = ServicoSistema.Ouvir();
                if(!palavar.equalsIgnoreCase("igual") && !palavar.equalsIgnoreCase("="))
                    conta += palavar;
                    //conta.add(palavar);
            }
            
            ScriptEngineManager mgr = new ScriptEngineManager();
            ScriptEngine engine = mgr.getEngineByName("JavaScript");
            ServicoSistema.Falar(engine.eval(conta));
        } catch (ScriptException | IOException ex) {
            Logger.getLogger(FazerConta.class.getName()).log(Level.SEVERE, null, ex);
        } catch (LineUnavailableException ex) {
            Logger.getLogger(FazerConta.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedAudioFileException ex) {
            Logger.getLogger(FazerConta.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NoPlayerException ex) {
            Logger.getLogger(FazerConta.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
}
